package icu.study.netty.server;

import icu.study.protoEntity.MsgProto;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.util.concurrent.ConcurrentHashMap;


public class ServerHandler extends SimpleChannelInboundHandler<MsgProto.Msg> {

    private static ConcurrentHashMap<String, Channel> channelGroup = new ConcurrentHashMap<>();

    private int index = 1;

    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, MsgProto.Msg msg) throws Exception {


        if (msg.getType() != MsgProto.Msg.Type.NULL) {
            System.out.println(index++ + ":" + msg + "," + msg.getType());
        }

    }


    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        Channel channel = ctx.channel();

//        channelGroup.put("", "");
        System.out.println("连接");
    }
}